import React, { useState } from 'react';

function UserForm() {
    const [user, setUser] = useState({
        name: '',
        email: '',
        age: 0
    });

    const handleInputChange = (field, value) => {
        setUser(prevUser => ({
            ...prevUser,
            [field]: value
        }));
    };

    const handleSubmit = () => {
        console.log('提交用户信息:', user);
    };

    return (
        <form onSubmit={handleSubmit}>
            <input
                type="text"
                placeholder="姓名"
                value={user.name}
                onChange={(e) => handleInputChange('name', e.target.value)}
            />
            <input
                type="email"
                placeholder="邮箱"
                value={user.email}
                onChange={(e) => handleInputChange('email', e.target.value)}
            />
            <input
                type="number"
                placeholder="年龄"
                value={user.age}
                onChange={(e) => handleInputChange('age', parseInt(e.target.value))}
            />
            <button type="submit">提交</button>
        </form>
    );
}
export default UserForm;